package codec;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.msgpack.MessagePack;
import protocol.NettyMessage;

public class MessagePachEncoder extends MessageToByteEncoder<Object> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Object msg, ByteBuf byteBuf) throws Exception {
        System.out.println("开始编码:"+System.currentTimeMillis());
        NettyMessage member = (NettyMessage) msg;
        MessagePack msgPack = new MessagePack();
        byte[] raw = msgPack.write(msg);
        byteBuf.writeBytes(raw);
        System.out.println("编码完成:"+System.currentTimeMillis());
    }
}
